local function set_lsp_server(lspconfig)
  local capabilities = require("cmp_nvim_lsp").default_capabilities()

  -- for ufo
  capabilities.textDocument.foldingRange = {
    dynamicRegistration = false,
    lineFoldingOnly = true,
  }

  -- local lsp_servers = require("plugin.plugins.lsp.lsp_server_list")
  -- for _, server_name in pairs(lsp_servers.servers) do
  --   --[[
  --     有 bug, 当时可以正常工作, 在启动时报错,信息如下,
  --     报错原因是因为在 config 下没有对应的 server_name的名字的配置 [server_name].lua 文件,就算没有任何配置也要创建,内容 return {}
  --   ]]
  --   --[[
  --     Not found mason
  --     Error detected while processing /home/timly/.config/nvim/init.lua:
  --     Invalid spec module: `plugin/plugins.mason`
  --     Expected a `table` of specs, but a `boolean` was returned instead
  --   ]]
  --   local language_status, language_config = pcall(require, "plugin.plugins.lsp.config." .. server_name)

  --   if not language_status then
  --     language_config = {}
  --   end

  --   local meger_config = vim.tbl_deep_extend("force", {
  --     capabilities = capabilities,
  --     flags = {
  --       debounce_text_changes = 150,
  --     },
  --   }, language_config);

  --   lspconfig[server_name].setup(meger_config)
  -- end

  -- =======================server setting begin===========================
  -- 启用 python 的 pyright 的服务, pyright  不知道为啥不工作
  -- npm install -g pyright 或者 pip install pyright
  -- python 语言的服务
  -- lspconfig.pyright.setup({
  --   capabilities = capabilities, -- 奇怪在 null_ls 有工作,使用 guard 就不工作,
  -- })
  lspconfig.pylsp.setup({
    capabilities = capabilities,
    settings = {
      pylsp = {
        plugins = {
          pycodestyle = {
            ignore = { "W391" },
            maxLineLength = 100,
          },
          flake8 = {
            enabled = true,
          },
          rope_autoimport = {
            enabled = true,
          },
          rope_completion = {
            enabled = true,
          },
        },
      },
    },
  })

  lspconfig.emmet_ls.setup({
    capabilities = capabilities,
  })

  -- clangd 语言的服务
  lspconfig.clangd.setup({
    capabilities = capabilities,
    cmd = { "clangd", "--offset-encoding=utf-16" },
    root_dir = function()
      return vim.fn.getcwd()
    end,
  })

  -- lua 语言的服务
  lspconfig.lua_ls.setup({
    capabilities = capabilities,
    settings = {
      Lua = {
        workspace = { checkThirdParty = false },
        telementry = { enable = false },
      },
      diagnostics = {
        globals = { "vim" },
      },
    },
  })

  -- toml 语言的服务
  lspconfig.taplo.setup({
    capabilities = capabilities,
  })

  --[[  使用单独的 rust-tools 插件配置
  -- rust 语言的服务
  lspconfig.rust_analyzer.setup({
    -- Server-specific settings. See `:help lspconfig-setup`
    capabilities = capabilities,
    root_dir = require("lspconfig/util").root_pattern("Cargo.toml"),
    filetypes = { "rust" },
    settings = {
      ["rust-analyzer"] = {
        -- enable clippy on save
        checkOnSave = {
          command = "clippy",
        },
        imports = {
          granularity = {
            group = "module",
          },
          prefix = "self",
        },
        cargo = {
          allFeatures = true,
          buildScripts = {
            enable = true,
          },
        },
        procMacro = {
          enable = true,
        },
      },
    },
  })
  ]]

  -- json 语言的服务
  lspconfig.jsonls.setup({
    capabilities = capabilities,
  })

  -- 查看语言服务
  -- :lua print(vim.inspect(vim.lsp.buf_get_clients()))
  -- =======================server setting end===========================
end

return {
  set_lsp_server = set_lsp_server
}
